package com.xmall.auth.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xmall.auth.dao.SysRoleResourceRelationMapper;
import com.xmall.auth.entity.SysRoleResourceRelation;
import com.xmall.auth.service.ISysRoleResourceRelationService;
import com.xmall.common.config.PlatformContant;
import com.xmall.common.config.PojoUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 后台角色资源关系表 服务实现类
 * </p>
 *
 * @author liuzh
 * @since 2020-06-14
 */
@Service
public class SysRoleResourceRelationServiceImpl extends ServiceImpl<SysRoleResourceRelationMapper, SysRoleResourceRelation> implements ISysRoleResourceRelationService {
        @Autowired
        SysRoleResourceRelationMapper sysRoleResourceRelationMapper;
        @Override
        public boolean saveSysRoleResourceRelation(SysRoleResourceRelation sysRoleResourceRelation) {
        PojoUtils.setSysProperties(sysRoleResourceRelation, PlatformContant.OpType.insert);
        return save(sysRoleResourceRelation);
        }

        @Override
        public boolean updateSysRoleResourceRelation(Long id , SysRoleResourceRelation sysRoleResourceRelation) {
        SysRoleResourceRelation oldSysRoleResourceRelation = getById(id);
        BeanUtils.copyProperties(sysRoleResourceRelation, oldSysRoleResourceRelation);
        PojoUtils.setSysProperties(oldSysRoleResourceRelation, PlatformContant.OpType.update);
        boolean update = update(
        oldSysRoleResourceRelation,
        new QueryWrapper<SysRoleResourceRelation>()
        .lambda().eq(SysRoleResourceRelation::getId, id)
        );
        return update;
        }

        @Override
        public boolean deleteSysRoleResourceRelation(Long id) {
        boolean b = removeById(id);
        return b;
        }

        @Override
        public SysRoleResourceRelation getSysRoleResourceRelation(Long id) {
        SysRoleResourceRelation sysRoleResourceRelation = getById(id);
        return sysRoleResourceRelation;
        }
}
